package com.example.customprogressdemo.slice;

import com.example.customprogressdemo.CustomProgress;
import com.example.customprogressdemo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.AttrHelper;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.utils.Color;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        // 获取布局组件
        DirectionalLayout layout = (DirectionalLayout) findComponentById(ResourceTable.Id_layout);
        // 创建自定义进度条组件
        CustomProgress progress = new CustomProgress(getContext());
        // 对样式进行配置
        progress.maxProgress = 200;
        progress.progress = 70;
        progress.textSize = vpToPx(20);
        progress.title = "学习进度还不足半哦~";
        progress.backCircleWidth = 20;
        progress.scheduleCircleWidth = 28;
        progress.progressColor = Color.RED;
        // 设置组件的布局
        DirectionalLayout.LayoutConfig config = new DirectionalLayout.LayoutConfig();
        config.width = vpToPx(300);
        config.height = vpToPx(300);
        progress.setLayoutConfig(config);
//        layout.addComponent(progress);
    }
    // 用来转换vp和px
    private int vpToPx(float p) {
       return AttrHelper.vp2px(p, getContext());
    }
    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
